package adapter;

import android.app.Activity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.itboye.hutoubenjg.R;

import java.util.List;

import bean.HuiFuTwoBean;
import util.GlideLoader;


/**
 * 帖子详情(带rid)  回复adapter
 */
public class HuiFuTwodapter extends android.widget.BaseAdapter implements View.OnClickListener{
    List<HuiFuTwoBean.RepeatInfoEntity> datas;
    int position;
    Activity context;
    ClickListener ClickListener;
    int fuid;
    public HuiFuTwodapter(Activity context, List<HuiFuTwoBean.RepeatInfoEntity> datas, int fuid, ClickListener ClickListener) {
        this.context = context;
        this.datas = datas;
        this.fuid=fuid;
        this.ClickListener=ClickListener;
    }

    @Override
    public int getCount() {
        return datas.size();
    }

    @Override
    public Object getItem(int position) {
        return datas.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {
        ViewHolder holder = null;
        if (convertView == null) {
            holder = new ViewHolder();
            convertView = LayoutInflater.from(context).inflate(R.layout.item_huifu_two, null);
            holder.img_name = (TextView) convertView.findViewById(R.id.img_name);
            holder.img_head = (ImageView) convertView.findViewById(R.id.img_head);
            holder.txt_content = (TextView) convertView.findViewById(R.id.txt_content);
            holder.txt_time = (TextView) convertView.findViewById(R.id.txt_time);
            holder.chlid_name = (TextView) convertView.findViewById(R.id.chlid_name);
            holder.chlid_content = (TextView) convertView.findViewById(R.id.chlid_content);
            holder.layout_chlid = (LinearLayout) convertView.findViewById(R.id.layout_chlid);
            holder.pinglun_img = (ImageView) convertView.findViewById(R.id.pinglun_img);

            convertView.setTag(holder);

        } else {
            holder = (ViewHolder) convertView.getTag();
        }
        GlideLoader.displayImageHeadCircular(datas.get(position).getUid()+"",holder.img_head);
       // XImageLoader.load(Const.IMAGE_HEAD_TWO + datas.get(position).getUid(), holder.img_head);
        holder.img_name.setText(datas.get(position).getUname());
        holder.txt_time.setText(datas.get(position).getCreate_time_desc());
        holder.txt_content.setText(datas.get(position).getContent());
        holder.chlid_content.setText(datas.get(position).getContent());
        if (fuid==datas.get(position).getTo_uid()){
            holder.layout_chlid.setVisibility(View.GONE);
            holder.txt_content.setVisibility(View.VISIBLE);
        }else{
            holder.layout_chlid.setVisibility(View.VISIBLE);
            holder.txt_content.setVisibility(View.GONE);
            holder.chlid_name.setText(datas.get(position).getTo_uname()+":");
        }
        holder.pinglun_img.setOnClickListener(this);
        holder.pinglun_img.setTag(position);
        return convertView;
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.pinglun_img:
                ClickListener.pinglun(v);
                break;
        }
    }

    public interface ClickListener {
        public void pinglun(View v);//评论
    }
    public static class ViewHolder {
        TextView img_name,txt_time,txt_content;
        LinearLayout layout_chlid;
        TextView chlid_name,chlid_content;

        ImageView pinglun_img;
        ImageView  img_head;

    }

}
